//////////////////////////////////////////
// Make Table S4
//////////////////////////////////////////


gl path "~/Dropbox/CovidTurnout/replication"

use "$path/original_data/analysis_file.dta", clear

drop age65_*
gen rv = age-65
gen treat = rv >= 0
forvalues j=2012(2)2020 {
	gen age65_`j' = (age >= 65) & (year == `j')
}

gen rv2 = rv^2
gen rv3 = rv^3
gen rv_treat = rv*treat
gen rv_treat2 = rv2*treat
gen rv_treat3 = rv3*treat

forval y = 2012(2)2020 {
	gen rv_y`y' = rv*(year==`y')
	gen rv2_y`y' = rv2*(year==`y')
	gen rv3_y`y' = rv3*(year==`y')
	gen rv_treat_y`y' = rv_treat*(year==`y')
	gen rv_treat2_y`y' = rv_treat2*(year==`y')
	gen rv_treat3_y`y' = rv_treat3*(year==`y')
}

* Turnout
reg voted age65_* i.year rv_y* rv_treat_y* [fw=obs] if age >= 55 & age <= 75, r
local b1_2020 = _b[age65_2020]
local se1_2020 = _se[age65_2020]
local b1_2018 = _b[age65_2018]
local se1_2018 = _se[age65_2018]
local b1_2016 = _b[age65_2016]
local se1_2016 = _se[age65_2016]
local b1_2014 = _b[age65_2014]
local se1_2014 = _se[age65_2014]
local b1_2012 = _b[age65_2012]
local se1_2012 = _se[age65_2012]
local n1 = e(N)

reg voted age65_* i.year rv_y* rv2_y* rv_treat_y* rv_treat2_y* [fw=obs] if age >= 55 & age <= 75, r
local b2_2020 = _b[age65_2020]
local se2_2020 = _se[age65_2020]
local b2_2018 = _b[age65_2018]
local se2_2018 = _se[age65_2018]
local b2_2016 = _b[age65_2016]
local se2_2016 = _se[age65_2016]
local b2_2014 = _b[age65_2014]
local se2_2014 = _se[age65_2014]
local b2_2012 = _b[age65_2012]
local se2_2012 = _se[age65_2012]
local n2 = e(N)

reg voted age65_* i.year rv*_y*  [fw=obs] if age >= 55 & age <= 75, r
local b3_2020 = _b[age65_2020]
local se3_2020 = _se[age65_2020]
local b3_2018 = _b[age65_2018]
local se3_2018 = _se[age65_2018]
local b3_2016 = _b[age65_2016]
local se3_2016 = _se[age65_2016]
local b3_2014 = _b[age65_2014]
local se3_2014 = _se[age65_2014]
local b3_2012 = _b[age65_2012]
local se3_2012 = _se[age65_2012]
local n3 = e(N)

reg voted age65_* i.year rv_y* rv2_y* rv_treat_y* rv_treat2_y*  [fw=obs] if age >= 45 & age <= 85, r
local b4_2020 = _b[age65_2020]
local se4_2020 = _se[age65_2020]
local b4_2018 = _b[age65_2018]
local se4_2018 = _se[age65_2018]
local b4_2016 = _b[age65_2016]
local se4_2016 = _se[age65_2016]
local b4_2014 = _b[age65_2014]
local se4_2014 = _se[age65_2014]
local b4_2012 = _b[age65_2012]
local se4_2012 = _se[age65_2012]
local n4 = e(N)

reg voted age65_* i.year rv*_y* [fw=obs] if age >= 45 & age <= 85, r
local b5_2020 = _b[age65_2020]
local se5_2020 = _se[age65_2020]
local b5_2018 = _b[age65_2018]
local se5_2018 = _se[age65_2018]
local b5_2016 = _b[age65_2016]
local se5_2016 = _se[age65_2016]
local b5_2014 = _b[age65_2014]
local se5_2014 = _se[age65_2014]
local b5_2012 = _b[age65_2012]
local se5_2012 = _se[age65_2012]
local n5 = e(N)




quietly {
	cap log close
	set linesize 255

	log using "$path/output/rd_table.tex", text replace
	
	noisily dis "\begin{table}[t]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{RD Estimates of the Effect of No-Excuse Absentee Voting on Turnout.}\label{tab:rd}}"
	noisily dis "\begin{tabular}{lcccccc}"
	noisily dis "\toprule\toprule"
	noisily dis " & \multicolumn{5}{c}{Turnout [0-100\%]} \\[2mm]"
	noisily dis " & (1) & (2) & (3) & (4) & (5) \\ \midrule"
	noisily dis "No Excuse (Age 65) $\times$ 2020 & " %4.2f `b1_2020' " & " %4.2f `b2_2020' " & " %4.2f `b3_2020' " & " %4.2f `b4_2020' " & " %4.2f `b5_2020' " \\"
	noisily dis "& (" %4.2f `se1_2020' ") & (" %4.2f `se2_2020' ") & (" %4.2f `se3_2020' ") & (" %4.2f `se4_2020' ") & (" %4.2f `se5_2020' ") \\[1mm]"
	
	noisily dis "No Excuse (Age 65) $\times$ 2018 & " %4.2f `b1_2018' " & " %4.2f `b2_2018' " & " %4.2f `b3_2018' " & " %4.2f `b4_2018' " & " %4.2f `b5_2018' " \\"
	noisily dis "& (" %4.2f `se1_2018' ") & (" %4.2f `se2_2018' ") & (" %4.2f `se3_2018' ") & (" %4.2f `se4_2018' ") & (" %4.2f `se5_2018' ") \\[1mm]"
	
	noisily dis "No Excuse (Age 65) $\times$ 2016 & " %4.2f `b1_2016' " & " %4.2f `b2_2016' " & " %4.2f `b3_2016' " & " %4.2f `b4_2016' " & " %4.2f `b5_2016' " \\"
	noisily dis "& (" %4.2f `se1_2016' ") & (" %4.2f `se2_2016' ") & (" %4.2f `se3_2016' ") & (" %4.2f `se4_2016' ") & (" %4.2f `se5_2016' ") \\[1mm]"
	
	noisily dis "No Excuse (Age 65) $\times$ 2014 & " %4.2f `b1_2014' " & " %4.2f `b2_2014' " & " %4.2f `b3_2014' " & " %4.2f `b4_2014' " & " %4.2f `b5_2014' " \\"
	noisily dis "& (" %4.2f `se1_2014' ") & (" %4.2f `se2_2014' ") & (" %4.2f `se3_2014' ") & (" %4.2f `se4_2014' ") & (" %4.2f `se5_2014' ") \\[1mm]"
	
	noisily dis "No Excuse (Age 65) $\times$ 2012 & " %4.2f `b1_2012' " & " %4.2f `b2_2012' " & " %4.2f `b3_2012' " & " %4.2f `b4_2012' " & " %4.2f `b5_2012' " \\"
	noisily dis "& (" %4.2f `se1_2012' ") & (" %4.2f `se2_2012' ") & (" %4.2f `se3_2012' ") & (" %4.2f `se4_2012' ") & (" %4.2f `se5_2012' ") \\[1mm]"
	
	noisily dis "BW & 10 & 10 & 10 & 20 & 20 \\"
	noisily dis "Spec & Linear & Sq & Cubic & Sq & Cubic \\"
	noisily dis "\# Observations & " %12.0fc `n1' " & " %12.0fc `n2' " & " %12.0fc `n3' " & " %12.0fc `n4' " & " %12.0fc `n5' "\\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{6}{p{.7\textwidth}}{\footnotesize Robust standard errors in parentheses. "
	noisily dis "Unit of observation is an individual by year. Running variable model estimated separately for each year.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off

}

